﻿using EntityPet;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PET.Tools;

namespace PET.Controllers
{
    /// <summary>
    /// 宠物保险控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class PetInsController : ControllerBase
    {
        private readonly PetDbContext pet;
        public PetInsController(PetDbContext petDb)
        {
            pet = petDb;
        }

        public Result Login(string? Account,string Password)
        {
            Result result = new Result();
            Pet_User? account = pet.Pet_User.Where(W => W.Account == Account && W.Password == Password).SingleOrDefault();
            if (account==null)
            {
                result.Code = 404;
                result.Name = "向静";
            }
            else
            {
                result.Code = 200;
            }
                return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public Result Adduser([FromBody] Pet_insurance ins)
        {
            Result result = new Result();

            pet.pet_Insurance.Add(ins);
            result.Data = pet.SaveChanges();
            return result;
        }

        [HttpPut]
        public Result Put([FromBody] Pet_insurance cover)
        {
            Result result = new Result();
            pet.pet_Insurance.Update(cover);
            result.Data = pet.SaveChanges();
            return result;
        }

    }
}
